<script setup lang="ts">
import { ref } from 'vue'
import { showToast } from 'vant'
const emit = defineEmits<{ (e: 'send', text: string): void }>()
const text = ref('')
const onSend = () => {
  if (!text.value.trim()) {
    showToast('请输入内容')
    return
  }
  emit('send', text.value.trim())
  text.value = ''
}
const onKeydown = (e: KeyboardEvent) => {
  if (e.key === 'Enter' && !e.shiftKey) {
    e.preventDefault()
    onSend()
  }
}
</script>

<template>
  <div class="ai-action">
    <van-field
      v-model="text"
      type="text"
      class="flex1"
      :border="false"
      placeholder="请输入提问内容"
      @keyup.enter="onSend"
    />
    <van-button type="primary" icon="arrow-up" round @click="onSend" />
  </div>
</template>

<style lang="scss" scoped>
.ai-action {
  position: fixed;
  left: 0;
  bottom: 50px;
  width: 100%;
  height: 60px;
  background-color: #fff;
  display: flex;
  align-items: center;
  padding: 0 16px;
  box-sizing: border-box;
  .flex1 {
    flex: 1;
    background-color: var(--cp-bg);
    border-radius: 25px;
    margin-right: 10px;
    padding: 8px 15px;
  }
}
</style>
